import {Module} from "vuex";
import Personal from "@/api/modules/Personal";
import {isEmpty} from "@/utils/helpers";

const app: Module<any, any> = {
    namespaced: true,
    state: {
        info: {},
    },
    getters: {},
    mutations: {
        setInfo: (state: any, data: any) => {
            state.info = data
        },
    },
    actions: {
        async getInfo({state, commit}, isForce = false) {
            if (isForce || isEmpty(state.info)) {
                const res: any = await Personal.info().catch(console.log)
                commit('setInfo', res.data || {})
            }
            return state.info;
        }
    },
}

export default app
